package com.project.m.api.busi.handlers.hicatcard;

import com.project.m.api.busi.config.BusiError;
import com.project.m.api.busi.db.entity.hicatcard.TService;
import com.project.m.api.busi.db.service.hicatcard.service.ServiceService;
import com.project.m.api.busi.handlers.DefaultBizParamChecker;
import com.project.m.api.busi.bean.hicatcard.ServiceListReq;
import com.project.m.api.busi.bean.hicatcard.ServiceListResp;
import com.project.m.api.common.biz.BizHandler;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class ServiceListQueryBizHandler extends DefaultBizParamChecker<ServiceListReq, ServiceListResp>
        implements BizHandler<ServiceListReq, ServiceListResp> {

    protected final org.slf4j.Logger logger = LoggerFactory.getLogger(ServiceListQueryBizHandler.class);

    @Autowired
    ServiceService serviceService;

    @Override
    public ServiceListResp handle(ServiceListReq bizRequest) throws Exception {

        ServiceListResp bizResp = new ServiceListResp();

        try {

            List<TService> serviceList = serviceService.findAllService();

            bizResp.setServiceList(serviceList);
            bizResp.setResult_code(BusiError.ERR_CODE_SUCCESS);
            return bizResp;

        } catch (Exception e) {
            logger.error("内部出错", e);
            bizResp.setResult_code(BusiError.ERR_CODE_DB_CONF);
            bizResp.setError_message(BusiError.ERR_MSG_DB_CONF);
            return bizResp;
        }
    }
}
